package com.company.graph;

import java.util.*;

/**
 * Created by v on 16-12-14.
 */
public class findCutPoint {
    private findCutPoint(){}

    static int n;
    static int m;
    static Map<Integer,LinkedList<Integer>> map;
    static boolean[] isVisited;
    static int[] serialNumber;

    static int head;

    //找到图中的割点
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);

        //输入边
        n=input.nextInt();
        //输入点,点的下标将从１开始
        m=input.nextInt();
        map=new HashMap<>();
        isVisited=new boolean[m+1];
        serialNumber=new int[m+1];

        for(int i=0;i<n;i++){
            int begin=input.nextInt();
            int end=input.nextInt();
            insert(begin,end);
            insert(end,begin);
        }
        dfs();
    }

    //深度优先搜索，初始化
    private static void dfs(){
        head=5;
        dfs(1,head);
    }

    //深度优先搜索,递归
    private static int dfs(int number,int begin){
        //给树的搜索顺序编号
        serialNumber[begin]=number;
        isVisited[begin]=true;
        int rbNumber=number;

        List<Integer> neighbors=map.get(begin);

        boolean z=true;

        for(int i=0;i<neighbors.size();i++){
            int neighbor=neighbors.get(i);

            //如果已经搜索过，则记录回滚编号
            if(isVisited[neighbor]){
                if(rbNumber>serialNumber[neighbor]){
                    rbNumber=serialNumber[neighbor];
                }
            }else {
                if(begin==head&&i>0&&z){
                    System.out.println(begin);
                    z=false;
                }

                int childRbNumber=dfs(number+1,neighbor);
                if(childRbNumber>=number&&begin!=head){
                    System.out.println(begin);
                }else if (childRbNumber<rbNumber){
                    rbNumber=childRbNumber;
                }
            }
        }

        return rbNumber;
    }

    static void insert(int begin ,int end){
        if(!map.containsKey(begin)){
            LinkedList<Integer> list=new LinkedList<>();
            map.put(begin,list);
        }

        map.get(begin).add(end);
    }
}
